/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.login;

import controller.register.CheckRegister;
import dao.TaiKhoanDAO;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import pojo.Taikhoan;
import template.choosePage;

/**
 *
 * @author vinh
 */
@ManagedBean(name = "login")
@SessionScoped
public class CheckTaiKhoan {

    /**
     * Creates a new instance of CheckTaiKhoan
     */
    static public String user = null;
    static public String pass = null;
    static public Taikhoan taikhoan = null;
    static boolean check = false;

    public CheckTaiKhoan() {
    }

    public String getUser() {
        return user;
    }

    public void setuser(String use) {
        user = use;
    }

    public String getPass() {
        return pass;
    }

    public void setpass(String pp) {
        pass = pp;
    }

    static public boolean getcheck(String username, String pass) {
        TaiKhoanDAO nddao = new TaiKhoanDAO();
        TaiKhoanDAO tkdao = new TaiKhoanDAO();
        List<Taikhoan> listtk = tkdao.getList();
        user = username;
        CheckTaiKhoan.pass = pass;
        for (int i = 0; i < listtk.size(); i++) {
            if (listtk.get(i).getTendangnhap().equals(username) && listtk.get(i).getMatkhau().equals(pass)) {
                check = true;

                taikhoan = listtk.get(i);
                break;
            }

        }
        return check;
    }

    static public boolean checkusername(String username) {
        TaiKhoanDAO nddao = new TaiKhoanDAO();
        TaiKhoanDAO tkdao = new TaiKhoanDAO();
        List<Taikhoan> listtk = tkdao.getList();
        user = username;
        for (int i = 0; i < listtk.size(); i++) {
            if (listtk.get(i).getTendangnhap().equals(username)) {
                return true;
            }
        }
        return false;
    }

    public void setLogout() {
        taikhoan = null;
        user = null;
        pass = null;
        check = false;
        CheckRegister.hoten=null;
        CheckRegister.noisong=null;
        CheckRegister.tendangnhap=null;
        CheckRegister.ngaysinh=1;
        CheckRegister.thangsinh=1;
        CheckRegister.namsinh=2000;
        choosePage.page="TrangChu";
    }

    public Taikhoan gettaikhoan() {
        return taikhoan;
    }
}
